str = new String( "The Gingham Dog" );

A good answer might be:

The new operator creates an object using the constructor String.


Two Steps with an Assignment Operator

Review: Two steps take place when an assignment operator is executed:

  1. The expression on the right of the "=" is evaluated.
  2. The result of evaluation is assigned to the variable on the left of the "=".

These steps happen like this:

   
    String str;    // name for a future object 
    
    str =      new String( "The Gingham Dog" ); 
    --+--      ----------------+--------------
      |                        |
      |                        
      |                        1.  An object is created using the constructor. 
      |                            The Java system keeps track of
      |                            how to find the object.       

      2. The way to find the object is stored in the variable str.

An object reference is information on how to find a particular object. The object is a chunk of main memory; a reference to the object is a way to get to that chunk of memory. The variable str does not actually contain the object, but contains information about where the object is.

Objects are created while a program is running. Each object has a unique object reference, which is used to find it. When an object reference is assigned to a variable, then that variable says how to find that object.

In diagrams, an object reference is usually shown as an arrow from the object reference variable to the object.

QUESTION 5:

What does a variable of a primitive type contain?